package cn.org.qary.controller.yaokaiing.front;

import cn.org.qary.entity.News;
import cn.org.qary.service.trait.yaokaiing.NewsService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller("front_NewsController")
@RequestMapping("front_news")
public class NewsController {
    @Autowired
    NewsService ns;

    @RequestMapping("show")
    @ResponseBody
    public JSONObject show(){
        List<News> list=ns.selectAll();
        JSONObject json=new JSONObject();
        json.put("json1",list);
        return json;
    }

    @RequestMapping("find/{id}")
    public String find(@PathVariable Integer id, Model model){
        News news=ns.selectById(id);
        model.addAttribute("title",news.getTitle());
        model.addAttribute("content",news.getContent());

        return "news";
    }
}
